
package com.photoeditor.demo.model.store.download;


import com.photoeditor.demo.util.AsyncTask;

import java.io.Serializable;

public class DownloadTask<T extends Serializable> extends AsyncTask<String, Integer, LoadInfo> {
    Downloader downloader = null;

    String urlstr = null;

    T mContentInfoBO;

    int mType;

    public DownloadTask(T contentInfoBO, int type) {
        this.mContentInfoBO = contentInfoBO;
        this.mType = type;
    }

    @Override
    protected void onPreExecute() {
    }

    @Override
    protected LoadInfo doInBackground(String... params) {
        urlstr = params[0];
        String localfile = params[1];
        int threadcount = Integer.parseInt(params[2]);
        // 初始化一个downloader下载器
        downloader = DownloadUtils.getInstance().getOrCreateDownloader(urlstr, localfile,
                threadcount, mContentInfoBO, mType);
        if (downloader.isdownloading())
            return null;
        // 得到下载信息类的个数组成集合
        return downloader.getDownloaderInfors();
    }

    @Override
    protected void onPostExecute(LoadInfo loadInfo) {
        if (loadInfo != null) {
            // 显示进度条
            // showProgress(loadInfo.getFileSize() , loadInfo.getComplete() ,
            // urlstr, v);
            // 调用方法开始下载
            downloader.download();
        }
    }
};
